<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:bi="http://java.sun.com/jsf/composite/bill">
    <h:body>
        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>
                    <h:panelGroup rendered="#{!channelStaffPaymentBillController.printPreview}" styleClass="alignTop" >
                        <p:panel header="Staff Payments" >
                            <h:panelGrid columns="1" >
                                <h:panelGrid columns="2" >
                                    <h:panelGrid columns="1">
                                        <p:autoComplete completeMethod="#{institutionController.completeAgency}" required="true" id="ins" 
                                        forceSelection="true" value="#{channelStaffPaymentBillController.institution}"
                                        var="pta" itemLabel="#{pta.name}" itemValue="#{pta}" />

                                        <p:calendar value="#{channelStaffPaymentBillController.fromDate}" navigator="false" pattern="dd MMMM yyyy" />
                                        <p:calendar value="#{channelStaffPaymentBillController.toDate}" navigator="false" pattern="dd MMMM yyyy" />
                                        <p:watermark value="Agent" for="ins"/>

                                        <p:commandButton ajax="false" value="Process" action="#{channelStaffPaymentBillController.calculateDueFeesAgency()}"/>
                                        <p:commandButton ajax="false" value="Clear" action="#{channelStaffPaymentBillController}"/>
                                    </h:panelGrid>



                                </h:panelGrid>


                                <p:dataTable   id="tblFee" value="#{channelStaffPaymentBillController.dueBillFees}" selection="#{channelStaffPaymentBillController.payingBillFees}" var="bf" rowKey="#{bf.id}" >

                                    <f:ajax  event="rowSelectCheckbox" execute="tblFee" listener="#{channelStaffPaymentBillController.performCalculations()}"   
                                             render=":#{p:component('ins')}  :#{p:component('lblDue')} :#{p:component('lblPay')} tblFee"  />  

                                    <f:ajax  event="rowUnselectCheckbox" execute="tblFee" listener="#{channelStaffPaymentBillController.performCalculations()}"   
                                             render=":#{p:component('ins')}  :#{p:component('lblDue')} :#{p:component('lblPay')} tblFee"  />  

                                    <f:ajax  event="toggleSelect" execute="tblFee" listener="#{channelStaffPaymentBillController.performCalculations()}"   
                                             render=":#{p:component('ins')}  :#{p:component('lblDue')} :#{p:component('lblPay')} tblFee"  />  

                                    <p:column selectionMode="multiple" ></p:column>

                                    <p:column headerText="Bill Id">
                                        <h:outputLabel value="#{bf.bill.insId}">
                                        </h:outputLabel>
                                    </p:column>

                                    <p:column headerText="Patient">
                                        <h:outputLabel value="#{bf.bill.patient.person.nameWithTitle}" rendered="#{bf.bill.patientEncounter eq null}"/>                                    
                                        <h:outputLabel value="#{bf.bill.patientEncounter.patient.person.nameWithTitle}"/>                                    
                                    </p:column>

                                    <p:column headerText="Booked on">
                                        <h:outputLabel value="#{bf.bill.createdAt}">
                                            <f:convertDateTime pattern="dd MMMM yyyy" />
                                        </h:outputLabel>
                                    </p:column>

                                    <p:column headerText="Paid or Not">
                                        <p:outputLabel rendered="#{bf.bill.billType eq 'ChannelCredit'}" value="Credit" style="color: red;"/>
                                        <p:outputLabel rendered="#{bf.bill.billType eq 'ChannelPaid'}" value="Paid" style="color: green;"/>
                                    </p:column>

                                    <p:column headerText="Charge" >
                                        <h:outputLabel  value="#{bf.feeValue}" />
                                    </p:column>

                                </p:dataTable>



                                <p:panel id="pTotals"  >
                                    <f:facet name="header" >
                                        <h:outputLabel value="Payment Details" />
                                    </f:facet>
                                    <h:panelGrid columns="2" >
                                        <h:outputLabel value="Total Due" ></h:outputLabel>
                                        <h:outputLabel id="lblDue" value="#{channelStaffPaymentBillController.totalDue}" >
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                        <h:outputLabel value="Paying This time" ></h:outputLabel>
                                        <h:outputLabel id="lblPay"  value="#{channelStaffPaymentBillController.totalPaying }" >
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>  
                                    </h:panelGrid>
                                </p:panel>
                                <h:panelGroup >

                                    <h:outputLabel value="Payment Method" ></h:outputLabel>
                                    <p:selectOneMenu  id="cmbPay" style="width: 400px;" value="#{channelStaffPaymentBillController.paymentMethod}" >
                                        <f:selectItem itemLabel="Please select a Payment method" />
                                        <f:selectItems value="#{enumController.paymentMethodsWithoutCredit}"/>
                                    </p:selectOneMenu>

                                    <p:commandButton ajax="false" value="Pay" action="#{channelStaffPaymentBillController.settleBillAgent()}" onclick="onSubmitButton();" >
                                        
                                    </p:commandButton>
                                </h:panelGroup>
                            </h:panelGrid>

                        </p:panel>
                    </h:panelGroup>

                    <h:panelGroup rendered="#{channelStaffPaymentBillController.printPreview}">


                        <p:commandButton value="Print" styleClass="noPrintButton" ajax="false" action="#" >
                            <p:printer target="gpBillPreview" ></p:printer>
                        </p:commandButton>
                        <p:commandButton ajax="false" value="Clear" action="#{channelStaffPaymentBillController.makenull()}" />

                                         <bi:staffBill id="gpBillPreview" controller="#{channelStaffPaymentBillController}" 
                                      bill="#{channelStaffPaymentBillController.current}" dup="false"/>
                    </h:panelGroup>



                </h:form>



            </ui:define>


        </ui:composition>


    </h:body>
</html>
